﻿var parent_type = "";
$(function () {
    parent_type = window.parent.page_type;
    //log.hide();
    if ($("#tbEditor").size() > 0) {
        var initEditor = function () {
            editAreaLoader.init({
                id: "tbEditor"	// id of the textarea to transform	
			    , start_highlight: true
			    , font_size: "10"
			    , font_family: "Arial, 宋体"
			    , allow_resize: "n"
			    , allow_toggle: false
			    , language: "zh"
			    , syntax: syntax
			    , toolbar: "save, |, charmap, |, search, go_to_line, |, undo, redo, |, select_font, |, change_smooth_selection, highlight, reset_highlight, |, help"
			    , syntax_selection_allow: "css,html,js,php,python,vb,xml,c,cpp,sql,basic,pas,brainfuck"
			    , save_callback: "texteditor.save_file"
			    , plugins: "charmap"
			    , charmap_default: "arrows",
                fullscreen: true
            });
        }
        initEditor();
    }
});
var texteditor = {};

texteditor.save_file = function (id, content) {
    var url = base_url + "FileExplorer/WebServices/TextFileService.asmx/" + "SaveFile";

    var data = "{ path: '" + file_path + "', content: '" + escape(content) + "'}";
    $.ajax({
        url: url,
        type: "POST",
        data: data,
        async: true,
        contentType: 'application/json; charset=utf-8',
        //dataType: 'json',
        success: function (obj) {
            log.log_text(obj.d.message, obj.d.success);
            alert(obj.d.message);
            if (obj.d.success) {
                window.parent.element.insert_file(ori_path);
                window.parent.log.log_text(file_path + "保存成功");
            } else {
                window.parent.log.log_text(file_path + "保存失败");
            }
        }
    });
}